from datetime import datetime

import django
from django.contrib.auth.models import AbstractUser
from django.db import models

'''
    author: 赵向阳
    date  : 2019/11/06
'''


class UserProfile(AbstractUser):
    nickname = models.CharField(max_length=32, verbose_name='用户昵称')
    gender = models.CharField(choices=(('girl', '女'), ('boy', '男')),
                              max_length=10, verbose_name="用户性别", default=True)
    phone = models.CharField(max_length=11, verbose_name='用户手机', null=True, blank=True)
    email = models.EmailField(unique=True, verbose_name='用户邮箱')
    is_start = models.BooleanField(default=False, verbose_name="是否激活")

    def __str__(self):
        return self.username

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name


class Address(models.Model):
    person_name = models.CharField(max_length=32, verbose_name='收件人', null=False, )
    person_address = models.CharField(max_length=256, verbose_name='收货地址')
    postcode = models.CharField(max_length=10, null=False, blank=True, verbose_name='邮编')
    person_phone = models.CharField(max_length=11, null=False, blank=True, verbose_name='收件人手机')
    a_user = models.ForeignKey(UserProfile, on_delete=models.CASCADE, blank=True)

    class Meta:
        verbose_name = '邮寄地址'
        verbose_name_plural = verbose_name


class EmailVerifyCode(models.Model):
    code = models.CharField(max_length=20, verbose_name='邮箱验证码')
    email = models.EmailField(max_length=200, verbose_name='验证码邮箱')
    send_type = models.IntegerField(choices=((1, 'register'), (2, 'forget'), (3, 'change')), verbose_name="验证码类型")
    add_time = models.DateTimeField(default=django.utils.timezone.now, verbose_name="添加时间")

    def __str__(self):
        return self.code

    class Meta:
        verbose_name = '邮箱验证码信息'
        verbose_name_plural = verbose_name
